package com.hu.service.impl;

import com.hu.config.comment.ResponseResult;
import com.hu.dal.mapper.UserMapper;
import com.hu.dal.pojo.User;
import com.hu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public ResponseResult insert(User user) {
        userMapper.insert(user);
        return ResponseResult.success("ok");
    }

    @Override
    public ResponseResult getAll(int page, int pageSize) {
        int offset = pageSize * (page - 1);
        List l=  userMapper.getAll(offset,pageSize);
        int count=userMapper.getCount();
        Map m =new HashMap();
        m.put("list",l);
        m.put("count",count);
        return ResponseResult.success("ok",m);
    }

    @Override
    public ResponseResult getById(int id) {
        return ResponseResult.success("ok",userMapper.getById(id));
    }

    @Override
    public ResponseResult update(User user) {
        userMapper.update(user);
        return ResponseResult.success("ok");
    }

    @Override
    public ResponseResult delete(int id) {
        userMapper.delete(id);
        return ResponseResult.success("ok");
    }
}
